package com.sun.blog.sunblog.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sun.blog.sunblog.base.BaseService;
import com.sun.blog.sunblog.mapper.UserMapper;
import com.sun.blog.sunblog.model.User;
import com.sun.blog.sunblog.service.UserService;

/**
 * 
 * @author Administrator
 * @date 2013-2-5 上午10:56:08
 */
@Service("userService")
public class UserServiceImpl extends BaseService implements UserService {

	@Autowired
	protected UserMapper userMapper;

	/**
     * [findAdminInfo 查询博主基本信息]
     * @return [博主信息]
     */
    public User findAdminInfo(){
        try{
            return userMapper.findAdminInfo();
        }catch(Exception e){
            log.error("查询博主信息出错", e);
            return null; 
        }
    }

    /**
     * [addUser 增加用户]
     * @param  user [用户信息]
     * @return      [添加结果： -1:出错,0:添加失败, 1:成功]
     */
    public Integer addUser(User user){
        try{
            return userMapper.addUser(user);
        }catch(Exception e){
            log.error("添加用户失败", e);
            return -1;
        }
    }
    /**
     * [findUserByEmail 根据邮箱查找用户]
     * @param  email [邮箱]
     * @return       [用户]
     */
    public User findUserByEmail(String email){
        try{
            return userMapper.findUserByEmail(email);
        }catch(Exception e){
            log.error("查找用户信息出错", e);
            return null; 
        }
    }

    /**
     * [updateUserinfo 更新用户信息]
     * @param  user [用户信息]
     * @return      [更新结果： -1:出错, 0:未找到对应User, 1:成功]
     */
    public Integer updateUserinfo(User user){
        try{
            return userMapper.updateUserinfo(user);
        }catch(Exception e){
            log.error("更新用户信息失败", e);
            return -1;
        }
    }
}
